﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using CNav.Domain;

namespace CNav.Model
{
    public class AddressModel
    {
        [Required, Display(Name = "Address line 1")]
        public string Address1 { get; set; }

        [Display(Name = "Address line 2")]
        public string Address2 { get; set; }

        [Required, Display(Name = "City")]
        public string City { get; set; }

        [Required, Display(Name = "Zip/Postcode")]
        public string PostalCode { get; set; }

        [Required, Display(Name = "Country")]
        public int CountryID { get; set; }

        [Required, Display(Name = "State")]
        public string State { get; set; }

        public IList<Country> CountryList { get; set; }

        public override string ToString()
        {
            var country = CountryList == null ? new Country() : CountryList.FirstOrDefault(c => c.ID == CountryID);
            return string.Format("{0}, {1}, {2}, {3}, {4}  {5}", Address1, Address2, City,
                PostalCode, State, country == null ? "" : country.Name);
        }
    }
}